package com.zhanbo.zhanbowymusic.main.mine.collections;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.flyco.tablayout.listener.OnTabSelectListener;
import com.mwx.baselib.base.BaseFragment;
import com.zhanbo.zhanbowymusic.R;
import com.zhanbo.zhanbowymusic.databinding.FragmentCollectionsBinding;

import java.util.ArrayList;

/**
 * 我的收藏fragment
 */
public class CollectionsFragment extends BaseFragment<FragmentCollectionsBinding> {
    private String[] mTitlesArrays = {"歌单", "播客"};
    private ArrayList<Fragment> fragments;
    @Override
    protected void init(Bundle savedInstanceState) {
        initView();
        initData();
        initListener();
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
            super.onLazyInitView(savedInstanceState);
    }

    @Override
    protected Object getLayout() {
        return R.layout.fragment_collections;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        fragments = new ArrayList<>();
        fragments.add(SongListCollectionsFragment.newInstance());
        fragments.add(PodcastsCollectionsFragment.newInstance());
        binding.tabCollections.setViewPager(binding.vpCollections, mTitlesArrays, getActivity(), fragments);
    }

    @Override
    protected void initListener() {
        binding.tabCollections.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                switchNum(position);
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
    }

    /**
     * 模块角标颜色更改
     *
     * @param position -模块坐标
     */
    public void switchNum(int position) {
        binding.numSingleSong.setTextColor(getResources().getColor(R.color.color_text));
        binding.numPodcasts.setTextColor(getResources().getColor(R.color.color_text));
        if (position == 0) {
            binding.numSingleSong.setTextColor(getResources().getColor(R.color.color_283248));
        } else if (position == 1) {
            binding.numPodcasts.setTextColor(getResources().getColor(R.color.color_283248));
        }
    }

    public static CollectionsFragment newInstance() {

        Bundle args = new Bundle();

        CollectionsFragment fragment = new CollectionsFragment();
        fragment.setArguments(args);
        return fragment;
    }
}